package com.example.baiduweishi.utils;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Environment;

import com.example.baiduweishi.MyApplication;

import java.io.File;


//普通JAVA类，是没有上下文
public class MyUtil {
    //返回共享首选项对象
    public static SharedPreferences getSharedPre(){
         //获取上下文  再获取共享首选项
        return MyApplication.getContext().getSharedPreferences("loginnew", Context.MODE_PRIVATE);


    }
    public boolean isSD(){
        if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
            return true;
        }
        return false;
    }


    //得到文件的路径
    public File getDir(){
        if (isSD()){
            return Environment.getExternalStorageDirectory();
        }
        return Environment.getDownloadCacheDirectory();
    }

    public static Intent getInstallintent(File file){
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        intent.setDataAndType(Uri.fromFile(file),"application/vnd.android.package-archive");
        MyApplication.getContext().startActivity(intent);
        return intent;
    }


}
